public class Demo2 {
    //3个线程  按照ABC顺序打印
    private static Object locker1=new Object();
    private static Object locker2=new Object();
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            System.out.println("A");
            synchronized (locker1){    //打印A后，通知打印B的线程
                locker1.notify();
            }
        });
        Thread t2=new Thread(()->{
           synchronized (locker1){
               try {
                   locker1.wait();   //等待打印A的线程结束，并接受通知
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("B");
           }
           synchronized (locker2){
               locker2.notify();   //B打印结束，通知打印C的线程
           }

        });
        Thread t3=new Thread(()->{
            synchronized (locker2){
                try {
                    locker2.wait();   //等待打印B的线程结束，并结束通知
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("C");
            }

        });
        t1.start();
        t2.start();
        t3.start();
    }
}
